package com.doit.demo03;

import java.util.function.Consumer;

public class test_consumer {
    public static void main(String[] args) {
        method("abc", new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s.toUpperCase());
            }
        });
        method("abc", (String s) -> System.out.println(s.substring(0, 2)));

        //简化
        method("abc", s -> System.out.println(s.toUpperCase()));
        method("abc", s -> System.out.println(s.substring(0, 2)));
        method2("abcd", s -> System.out.println(s.toUpperCase())
                , s -> System.out.println(s.toLowerCase()));
    }

    public static void method(String s, Consumer<String> c) {
        c.accept(s);
    }

    public static void method2(String s, Consumer<String> c1, Consumer<String> c2) {
        c1.andThen(c2).accept(s);
    }
}
